<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.io.*,java.text.*,java.util.*,java.sql.*,java.text.SimpleDateFormat,java.text.DateFormat,java.util.Date,javax.servlet.*,javax.servlet.http.*,DBstep.iDBManager2000.*" %>
<%
  //自动获取OfficeServer和OCX文件完整URL路径
  String mHttpUrlName=request.getRequestURI();
  String mScriptName=request.getServletPath();
  String mServerName="OfficeServer";
  String mServerUrl="http://"+request.getServerName()+":"+request.getServerPort()+mHttpUrlName.substring(0,mHttpUrlName.lastIndexOf(mScriptName))+"/"+mServerName;//取得OfficeServer文件的完整URL
%>

<html>
<head>
<title>模板书签填充</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="../../js/WebOffice.js"></script>
<script type="text/javascript">
 	var WebOfficeObject = new WebOffice2015(); //创建WebOffice对象
</script>

<script language="javascript">
	  function Load()
		{
			try
			{

				WebOfficeObj.WebUrl = "<%=mServerUrl%>";
			  WebOfficeObj.UserName = "演示人";
			WebOfficeObj.FileName = "template.doc";
		    WebOfficeObj.FileType = ".doc";            //FileType:文档类型  .doc  .xls
		    WebOfficeObj.DebugMode = false;						//开启or关闭调试模式  true：开启  false：关闭
		    WebOfficeObj.ShowWindow = false;					//显示/隐藏进度条
		     WebOfficeObj.EditType = "1";				//设置加载文档类型 0 锁定文档，1无痕迹模式，2带痕迹模式
		    WebOfficeObj.ShowMenu = 0;
		    WebOfficeObj.ShowToolBar = 0;
		    WebOfficeObj.SetCaption(WebOfficeObj.UserName + "正在编辑文档");
		    SetGraySkin();			//设置控件皮肤
			if(WebOfficeObject.WebOpen())
			{
				 WebOfficeObj.WebObject.IsModify(0);
			  	StatusMsg(WebOfficeObj.Status);
			}
			}
			catch(e){
 	     	alert(e.description);
 	    }
		}
	  

		//文档模板书签填充
		function WebTemplateBMFilling()
		{
			var rg;
			try {
				//开始遍历当前打开的文档中存在的书签数，然后根据对应的书签名进行填充
				for (var i = 1; i <= WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Count; i++) {
					if (WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item(i).Name == "Caption") {
						rg = WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item("Caption").Range;
						rg.Text = "关于信息化建设的题案";
						WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Add("Caption", rg);
					}
					else if (WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item(i).Name == "Content") {
						rg = WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item("Content").Range;
						rg.Text = "公文内容：请详细填写";
						WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Add("Content", rg);
					}
					else if (WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item(i).Name == "Description") {
						rg = WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item("Description").Range;
						rg.Text = "计算机、信息、网络";
						WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Add("Description", rg);
					}
					else if (WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item(i).Name == "Sec") {
						rg = WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item("Sec").Range;
						rg.Text = "绝密";
						WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Add("Sec", rg);
					}
					else if (WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item(i).Name == "Subject") {
						rg = WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Item("Subject").Range;
						rg.Text = "内部公文";
						WebOfficeObject.WebObject.ActiveDocument.Bookmarks.Add("Subject", rg);
					}
				}
				StatusMsg("文档模板书签填充成功");
			} catch(e) {
				StatusMsg("文档模板书签填充失败");
			}
		}

		//设置页面中的状态值
 		function StatusMsg(mValue){
 	   	try{
 	   		document.getElementById('StatusBar').value = mValue;
	   	}catch(e){
	     	return false;
	   	}
		}
		
		function OnUnLoad(){
			WebOfficeObj.WebClose();
		}

</script>

<!--以下是多浏览器的事件方法 -->
<script>
function OnReady(){
 WebOfficeObj.setObj(document.getElementById('WebOffice'));//给2015对象赋值
 //Load();//避免页面加载完，控件还没有加载情况
 window.onload = function(){Load();} //IE和谷歌可以直接调用Load方法，火狐要在页面加载完后去调用
}
</script>

<script language="javascript" for=WebOffice event="OnReady()">
	 WebOfficeObject.setObj(document.getElementById('WebOffice'));
   Load();//避免页面加载完，控件还没有加载情况
</script>
</head>

<body onbeforeunload="OnUnLoad()" onUnload="OnUnLoad();">
	<div style="width: 100%; height: 100%">
		<div style="width: 100%;">
			<input style="color:Red;" type=button value="书签填充" onclick="WebTemplateBMFilling()">
			<input style="color:Red;" id="StatusBar" type="text" name="StatusBar" readonly  style="WIDTH:40%">&nbsp;|←状态信息
		</div>
		<div style="width: 100%; height: 98%;" ><script src="../../js/iWebOffice2015.js"></script></object></div>
	</div>
</body>
 <script language="javascript">
 var i = document.getElementById('WebOffice').height =document.documentElement.clientHeight-50 +"px";
 document.getElementById('WebOffice').style.height = i;
 window.onresize = function(){
 var i = document.getElementById('WebOffice').height =document.documentElement.clientHeight-50 +"px";
 document.getElementById('WebOffice').style.height = i;
 };
 </script>
</html>